package com.prnasia.cloud.spring.amp.controller;

import com.prnasia.cloud.spring.entity.StoryEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Wen Gao on 2019/4/8.
 */
@RestController
@RefreshScope
public class AmpController {

    @Value("${sendmail.url}")
    private String sendmailUrl;
    @Value("${sendmail.username}")
    private String sendmailUsername;
    @Value("${sendmail.password}")
    private String sendmailPassword;

    @GetMapping("story/{id}")
    public StoryEntity get(@PathVariable int id) {
        return new StoryEntity(id, "headline" + id);
    }

    @PostMapping("story")
    public StoryEntity add(@RequestBody StoryEntity storyEntity) {
        System.out.println("AMP add a story : " + storyEntity);
        return storyEntity;
    }

    @GetMapping("getSendmailConfig")
    public String getSendmailConfig() {
        return sendmailUrl + " " + sendmailUsername + " " + sendmailPassword;
    }

}
